<?php
$this->headTitle('Phân quyền','append');
?>
<div class="grid">
    <div class="breadcrumbs">
        <a class="item-1" href="/index">Trang chủ</a> › 
        <a class="item-2" href="/admin/role"><?php $title = $this->headTitle(); if(isset($title[0])) echo $title[0]; ?></a> › 
        <span>Sửa</span>
        <div class="clear-both"></div>
    </div>
    <div class="box header">Sửa quyền mới</div>
    <div class="box content">
        <?php
            if(isset($this->mess)){
                if($this->flag == 'success')
                    echo '<div class="notification success">',$this->mess,'</div>';
                elseif($this->flag == 'alert')
                    echo '<div class="notification alert">',$this->mess,'</div>';
                else
                    echo '<div class="notification error">',$this->mess,'</div>';
            }
        ?>
        <form id="form" class="form-option" method="post" action="" enctype="multipart/form-data" name="form">
            <dl class="zend_form">
                <dt><label>Tên quyền</label></dt>
                <dd><input type="text" id="roleName" name="roleName" value="<?php echo $this->roleCheck['roleName'];?>"/></dd>
                <div class="clear-both"></div>
                <dt><label>Xem thông tin user</label></dt>
                <dd>
                    <div class="option-wrapper">
                        <div class="fieldset">
                            <div class="legend"><input type="checkbox" id="check_all_userInfo"/><label>Chọn hết</label></div>
                            <div class="fieldset-content">
                                <ul>
                                    <li><input type="checkbox" name="viewPhone" value="1" <?php echo ($this->roleCheck['viewPhone'] == 1) ? 'checked="checked"' : '';?>/><label>Xem SĐT</label></li>
                                    <li><input type="checkbox" name="viewEmail" value="1" <?php echo ($this->roleCheck['viewEmail'] == 1) ? 'checked="checked"' : '';?>/><label>Xem Email</label></li>
                                </ul>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </dd>
                <div class="clear-both"></div>
                <dt><label>Dự án</label></dt>
                <dd>
                    <div class="option-wrapper">
                        <div class="fieldset">
                            <div class="legend"><input type="checkbox" id="check_all_gameId"/><label>Chọn hết</label></div>
                            <div class="fieldset-content">
                                <ul>
                                <?php 
                                    $gameList = $this->roleCheck['gameId'];
                                    $gameList = json_decode($gameList);
                                    foreach($this->gameList as $game){
                                        if(is_array($gameList) && in_array($game['gameId'],$gameList))
                                            echo "<li><input type='checkbox' class='gameId' name='gameId[]' value='{$game['gameId']}' checked='checked'><label>{$game['gameName']}</label></li>";
                                        else
                                            echo "<li><input type='checkbox' class='gameId' name='gameId[]' value='{$game['gameId']}'><label>{$game['gameName']}</label></li>";
                                    }
                                ?>
                                </ul>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </dd>
                <div class="clear-both"></div>
                <dt><label>Chức năng admin</label></dt>
                <dd>
                    <div class="option-wrapper">
                        <div class="fieldset">
                            <div class="legend"><input type="checkbox" id="check_all_resource_admin"/><label>Chọn hết</label></div>
                            <div class="fieldset-content">
                            <ul>
                            <?php 
                                $resourceList = $this->roleCheck['resourceId'];
                                $resourceList = json_decode($resourceList);
                                foreach($this->resourceList as $resource){
                                    if($resource['moduleName'] == 'admin'){
                                        if(isset($resourceList) && is_array($resourceList) && in_array($resource['resourceId'],$resourceList))
                                            echo "<li><input type='checkbox' class='resourceIdAdmin' name='resourceId[]' value='{$resource['resourceId']}' checked='checked'><label>{$resource['resourceName']}</label></li>";
                                        else
                                            echo "<li><input type='checkbox' class='resourceIdAdmin' name='resourceId[]' value='{$resource['resourceId']}'><label>{$resource['resourceName']}</label></li>";
                                    }
                                }
                            ?>
                            </ul>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </dd>
                <div class="clear-both"></div>
                <dt><label>Chức năng game</label></dt>
                <dd>
                    <div class="option-wrapper">
                        <div class="fieldset">
                            <div class="legend"><input type="checkbox" id="check_all_resource_default"/><label>Chọn hết</label></div>
                            <div class="fieldset-content">
                            <ul>
                            <?php 
                                $resourceList = $this->roleCheck['resourceId'];
                                $resourceList = json_decode($resourceList);
                                foreach($this->resourceList as $resource){
                                    if($resource['moduleName'] == 'default'){
                                        if(isset($resourceList) && is_array($resourceList) && in_array($resource['resourceId'],$resourceList))
                                            echo "<li><input type='checkbox' class='resourceIdDefault' name='resourceId[]' value='{$resource['resourceId']}' checked='checked'><label>{$resource['resourceName']}</label></li>";
                                        else
                                            echo "<li><input type='checkbox' class='resourceIdDefault' name='resourceId[]' value='{$resource['resourceId']}'><label>{$resource['resourceName']}</label></li>";
                                    }
                                }
                            ?>
                            </ul>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </dd>
                <?php 
                if(isset($this->configApp->channel)){ 
                $arrChannelList = $this->configApp->channel->toArray();
                ?>
                <div class="clear-both"></div>
                <dt><label>Channel disabled</label></dt>
                <dd>
                    <div class="option-wrapper">
                        <div class="fieldset">
                            <div class="legend"><input type="checkbox" id="check_all_channel_default"/><label>Chọn hết</label></div>
                            <div class="fieldset-content">
                            <ul>
                            <?php 
                                if(isset($this->roleCheck['channelDisabled']))
                                    $channelDisabled = json_decode($this->roleCheck['channelDisabled']);
                                foreach ($arrChannelList as $key=>$channel){
                                    $cls = '';
                                    if(isset($channelDisabled) && is_array($channelDisabled) && $channelDisabled && in_array($key, $channelDisabled))
                                        $cls = 'checked="checked"';
                                    echo "<li><input type='checkbox' class='channelDefault' name='channelDisabled[]' value='{$key}' $cls><label>{$channel['name']}</label></li>";
                                }
                            ?>
                            </ul>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </dd>
                <?php } ?>
                <div class="clear-both"></div>
                <dt><label>Trang chủ game</label></dt>
                <dd>
                    <div class="option-wrapper">
                        <div class="fieldset">
                            <div class="fieldset-content">
                            <ul>
                            <?php 
                                foreach ($this->resourceList as $resource){
                                    if($resource['moduleName'] == 'default' && ($resource['actionName'] == 'index' || $resource['actionName'] == 'server') && $this->roleCheck['homepage'] == $resource['menu'])
                                        echo "<li><input type='radio' class='radio' name='homepage' value='{$resource['menu']}' checked='checked'><label>{$resource['resourceName']}</label></li>";
                                    elseif($resource['moduleName'] == 'default' && ($resource['actionName'] == 'index' || $resource['actionName'] == 'server'))
                                        echo "<li><input type='radio' class='radio' name='homepage' value='{$resource['menu']}'><label>{$resource['resourceName']}</label></li>";
                                }
                            ?>
                            </ul>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </dd>
                <div class="clear-both"></div>
                <dt></dt>
                <dd id="submit-element">
                    <input value="Lưu thay đổi" class="button" type="submit" />
                    <input value="Reset" class="button" type="reset"/>
                </dd>
            </dl>
        </form>
    </div>
</div>